home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_065 / prep / str.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  716b  |  41 lines

  1. /* A few string functions missing from Sun unix */
  2.  
  3. #include <stdio.h>
  4. #include "string.h"
  5.  
  6. /* Find the first occurrence of c in string */
  7. char    *strchr( s, c )
  8. char    *s, c ;
  9. {
  10. int    length, i ;
  11.     length = strlen(s) ;
  12.  
  13.     for ( i=0; i<=length; i++ ) if ( s[i] == c ) return( &s[i] ) ;
  14.     return( NULL ) ;
  15. }
  16.  
  17. /* find the index of the first char in s1 that is not in s2 */
  18. int    strspn( s1, s2 )
  19. char    *s1, *s2 ;
  20. {
  21. int    i ;
  22.  
  23.     for ( i=0 ; s1[i] != NULL ; i++ ) {
  24.         if ( NULL == strchr(s2,s1[i]) ) break ;
  25.         }
  26.     return(i) ;
  27. }
  28.  
  29.  
  30. /* find the index of the first char in s1 that is in s2 */
  31. int    strcspn( s1, s2 )
  32. char    *s1, *s2 ;
  33. {
  34. int    i ;
  35.  
  36.     for ( i=0 ; s1[i] != NULL ; i++ ) {
  37.         if ( NULL != strchr(s2,s1[i]) ) break ;
  38.         }
  39.     return(i) ;
  40. }
  41.